package com.utility.project.controller;

import com.utility.project.common.base.R;
import com.utility.project.param.OrderParam;
import com.utility.project.service.IYsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yangzhiguo
 * @date 2024-06-13
 * @description 订单表
 */
@Api(tags = "订单表")
@RestController
@RequestMapping("/ysOrder")
public class YsOrderController {

    @Resource
    private IYsOrderService ysOrderService;

    @ApiOperation("通过ID查询订单数据")
    @GetMapping("/queryById")
    public R queryById(@RequestParam("id")Long id){
        return R.ok(ysOrderService.getById(id));
    }

    @ApiOperation("新增订单数据")
    @PostMapping("/save")
    public R save(@RequestBody OrderParam param){
        Integer res = ysOrderService.saveOrder(param);
        if(res > 0) {
            return R.okWithMsg("订单保存成功");
        }else{
            return R.fail("订单保存失败");
        }
    }

    @ApiOperation("修改订单状态")
    @PostMapping("/editOrderStatus")
    public R editOrderStatus(@RequestBody OrderParam param){
        Integer res = ysOrderService.editOrderStatus(param);
        if(res > 0) {
            return R.okWithMsg("订单保存成功");
        }else{
            return R.fail("订单保存失败");
        }
    }

    @ApiOperation("通过username查询订单数据")
    @GetMapping("/queryByUsername")
    public R queryByUsername(@RequestParam("username") @ApiParam("用户名，对应于小程序openId") String username){
        return R.ok(ysOrderService.queryByUsername(username));
    }
    
}
